/*
 * @Description: In User Settings Edit
 * @Author: YJP
 * @Date: 2019-08-23 11:48:54
 * @LastEditTime: 2021-11-19 10:10:44
 * @LastEditors: Please set LastEditors
 */
const path = require('path');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; //Webpack包文件分析器
const externals = {
	vue: 'Vue',
    'vue-router': 'VueRouter',
    vuex: 'Vuex',
    'vant': 'vant',
	axios: 'axios',
	pako:'pako',
	echarts:'echarts',
	'vue-echarts':'VueECharts',
	'better-scroll':'BScroll',
	'vue-scroller':'VueScroller',
	Sortable:'sortablejs',
	vuedraggable:'vuedraggable',
	'mint-ui': 'MINT',
}
const cdn = {
	dev:{

	},
	build: {
        css: [
            '//cdn.jsdelivr.net/npm/vant@2.8.4/lib/index.css'
        ],
        js: [
            '//cdn.bootcss.com/vue/2.6.10/vue.min.js',
            '//cdn.bootcss.com/vue-router/3.1.3/vue-router.min.js',
            '//cdn.bootcss.com/vuex/3.1.1/vuex.min.js',
            '//cdn.bootcss.com/axios/0.19.0/axios.min.js',
			'//cdn.jsdelivr.net/npm/vant@2.8.4/lib/vant.min.js',
			'//cdn.bootcss.com/pako/1.0.10/pako.js',
			'//cdn.jsdelivr.net/npm/echarts@4.1.0/dist/echarts.js',
			'//cdn.jsdelivr.net/npm/vue-echarts@4.0.2',
			'//unpkg.com/better-scroll@2.4.2/dist/better-scroll.js',
			'//unpkg.com/vue-scroller@2.2.4/dist/vue-scroller.min.js',
			'//cdn.jsdelivr.net/npm/sortablejs@1.8.4/Sortable.min.js',
			'//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js',
			'//unpkg.com/mint-ui/lib/index.js',//mint-ui
        ]
    }
}
module.exports = {
	//基本路径
    publicPath:'./',//vue-cli3.3+新版本使用
	//输出文件目录
	outputDir: 'dist',
	//放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
	assetsDir: 'static',
	//是否使用包含运行时编译器的 Vue 构建版本
	runtimeCompiler: false,
	//是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用，仅作用于生产构建，在适当的时候开启几个子进程去并发的执行压缩
	parallel: require('os').cpus().length > 1,
	//生产环境是否生成 sourceMap 文件，一般情况不建议打开
	productionSourceMap: false,
	// webpack配置
	//对内部的 webpack 配置进行更细粒度的修改 https://github.com/neutrinojs/webpack-chain see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
	chainWebpack: config => {
		// 修复HMR
        config.resolve.symlinks(true);
	},
	//调整 webpack 配置 https://cli.vuejs.org/zh/guide/webpack.html#%E7%AE%80%E5%8D%95%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F
	configureWebpack: config => {
		
		// 生产环境使用cdn,常用的包隔离不打包
		if(process.env.NODE_ENV === 'production'){
			// externals里的模块不打包
            Object.assign(config, {
				externals: externals,
				devtool: 'source-map'
			})
			const pluginsPro = [
				//	Webpack包文件分析器(https://github.com/webpack-contrib/webpack-bundle-analyzer)
				new BundleAnalyzerPlugin(),
			]
			config.plugins = [...config.plugins,...pluginsPro];
		}
	},
	chainWebpack: config => {
		// 对vue-cli内部的 webpack 配置进行更细粒度的修改。
		// 添加CDN参数到htmlWebpackPlugin配置中， 详见public/index.html 修改
		config.plugin('html').tap(args => {
			if (process.env.NODE_ENV === 'production') {
				args[0].cdn = cdn.build
			}
			if (process.env.NODE_ENV === 'development') {
				// args[0].cdn = cdn.dev
			}
			return args
		})
	},
	css: {
		// 启用 CSS modules
		modules: false,
		// 是否使用css分离插件/样式热更新
		extract: process.env.NODE_ENV === 'production'? true : false,
		// 开启 CSS source maps，一般不建议开启
		sourceMap: false,
		// css预设器配置项
		loaderOptions: {
            css: {},
            postcss: {
              plugins: [
                autoprefixer({
                  overrideBrowserslist: ['Android >= 4.0', 'iOS >= 7'],
                  grid:true
                }),
                pxtorem({
                  rootValue: 75,
				  propList: ['*'],
				  selectorBlackList: ["mint-","van-","odometer-","el-","orgchart","dplayer-","vs-"]
				})
              ]
            }
        }
	},
	pluginOptions: {
		//为了 配置全局less变量生效
        'style-resources-loader': {
          preProcessor: 'less',
          patterns: [path.resolve(__dirname, './src/assets/css/theme.less')]
        }
    },
	// webpack-dev-server 相关配置 https://webpack.js.org/configuration/dev-server/
	devServer: {
		open: true, //配置自动启动浏览器  http://172.16.1.12:7071/rest/mcdPhoneBar/ 
		hotOnly: true, // 热更新
		proxy: { //配置自动启动浏览器
			'/interface':{
				target:"http://api.pingcc.cn/",
				changeOrigin: true,
				ws:false,
				pathRewrite:{
					'^/interface':''
				}
			},
			'/open':{
				target:"https://api.apiopen.top/",
				changeOrigin: true,
				ws:false,
				pathRewrite:{
					'^/open':''
				}
			},
			'/ws':{
				target:"https://apis.map.qq.com/ws",
				changeOrigin: true,
				ws:false,
				pathRewrite:{
					'^/ws':''
				}
			},
			'/travel': {
				target: 'http://chexiaojiang.uqipay.com/travel',
				changeOrigin: true,
				ws:false,
				pathRewrite:{
					'^/travel':''
				}
			},
		}
	},
	//transpileDependencies:['vue-radial-progress','vue-scroller','vue-waterfall2','vuedraggable','vue-touch-ripple','vue-echarts','echarts'],//babel转义依赖
	
};